<template>
  <mt-button class="my-button send-code" @click="doCount(count)" :disabled="isDisabled">{{content}}</mt-button>
</template>

<script>
export default {
  name: 'countDown',
  props: {
    val: String,
    count: Number
  },
  data() {
    return {
      content: this.val,
      curCount: this.count,
      isDisabled: false
    };
  },
  mounted() {
    console.log(this);
  },
  computed: {},
  methods: {
    doCount() {
      this.$emit('do-count');
    },
    // 倒计时
    setRemainTime() {
      this.content = `${this.curCount}秒后重发`;
      let InterValObj = setInterval(() => {
        if (this.curCount === 0) {
          this.isDisabled = false;
          clearInterval(InterValObj);
          this.curCount = this.count;
          this.content = this.val;
        } else {
          this.curCount--;
          this.content = `${this.curCount}秒后重发`;
        }
      }, 1000);
    }
  }
};
</script>

<style lang="less" scoped>
.send-code {
  width: 100px;
  padding: 8px 3px;
  margin: 0;
  margin-left: 5px;
}
</style>
